<!DOCTYPE html>
<html>
  <head>
  	<div th:include="base-libs :: base-libs" />
    <title>rwgl.html</title>
	
    <meta name="keywords" content="keyword1,keyword2,keyword3">
    <meta name="description" content="this is my page">
    <meta name="content-type" content="text/html; charset=UTF-8">
    
    <style>
    	.laydate-icon{
			width:87% !important;
			padding-left: 5px;
			line-height: 28px;
			background-color: #fff;
			height: 28px;
			border: 1px solid #B6B6B6;
			border-radius: 5px;
		}
		.spanBtn{
			font-weight: bold;
	    	color: blue;
	    	cursor:pointer;
		}
		.tabs-wrap>.tabs>li>a{
			border-left:1px solid #438EB9!important;
			border-right:1px solid #438EB9!important;
			border-top:1px solid #438EB9!important;
		}
		.north{
			overflow:hidden;
			height:130px;
			border:0;
			background:#f8f8f8
		}
		/*浮雕字体css*/
		.fdztCss{
			text-shadow: 1px 1px 0 rgba(255, 255, 255, .7);
			color:#ccc;
		}
    </style>
    
    <script th:inline="javascript">
    	var tdxxArr = [[${tdxxArr}]];
    </script>
    <script>
    	$(function(){
    		$(this).registerManagerPage();
    		initView();
    		initData();
    	})
    	
    	function initData(){
    		//查询分配服务列表
    		$("#btnQuery_fpfw").trigger("click");
    		enterToQuery(btnQueryHandler_fpfw);
    	}
    	
    	function initView(){
    		$('#tabs').tabs({
				border: true,
			    fit: true,
			    tabWidth: "160",
				onSelect: function(title,index){
					var nowSelectTab = $(this).tabs('getTab',index); //获取到当前激活的tab
					var tableId = nowSelectTab.find("table").eq(1).attr("id");
					if(!StringUtils.isEmpty(tableId)){
						initTableMethod[tableId](); //初始化table
					}
					if(index==1){
						$("#btnQuery_rwgl").trigger("click");
						enterToQuery(btnQueryHandler_rwgl);
					}else{
						enterToQuery(btnQueryHandler_fpfw);
					}
				}
			})
			//查询条件初始化-团队
    		$(".tdxxSelect").createOptions(tdxxArr,{textField : "TDMC" , valueField : "TDID"});

			//查询条件-服务包
			$.QuickRemote.AjaxJson(contextRoot + "wdqyhz/queryFwbxxByUserInfo", function(result){
				/*var $FWBID = $("#FWBID");
				 $.each(result, function(i, item){
				 var option = $("<option>").html(item.FWBMC).val(item.FWBID);
				 $FWBID.append(option);
				 })*/
                $("#FWBID").createOptions(result,{textField:"FWBMC",valueField:"FWBID"});
			}, {USERID: parent.userInfo.USERID, TDJS:1,TDZT:1});
			initTableMethod.qyhzTable();
    		$("body").css("visibility","visible");
			//查询时间限制
            timeSetting('QYSJ_start','QYSJ_end');
    	}

        //时间段互相限制
        function timeSetting(startTagId,endTagId){
            var startTimeObj = {
                elem: '#'+ startTagId ,
                choose: function(datas){
                    endTimeObj.min = datas;
                }
            };
            laydate(startTimeObj);

            var endTimeObj = {
                elem: '#'+ endTagId,
                choose: function(datas){
                    startTimeObj.max = datas;
                }
            };
            laydate(endTimeObj);
        }
    	
    	/** 分配服务查询  */
       	function btnQueryHandler_fpfw(){
       		$("#qyhzTable").datagrid({"url": contextRoot + "wdqyhz/queryPage.service"});
       	}
    	
       	/** 任务管理查询  */
	   	function btnQueryHandler_rwgl(){
	   		$("#yfprwTable").datagrid({"url": contextRoot + "wdqyhz/queryYfprwByPage.service"});
	   	}
    	
	   	/** 查看详细服务  */
	   	function toCkfw(qyData){
	   		StoreCache.setCache("qyData",qyData);
	   		StoreCache.setCache("backUrl","rwgl.html");
	   		$.QuickUrlUtils.redirectUrl("ckfw.html");
	   	}
	   	
	   	/** 分配服务  */
	   	function handoutTask(qyData){
	   			StoreCache.setCache("qyData",qyData);
	   			
	   			parent.layer.open({
					  type: 2,
					  area: ["80%", "80%"],
					  content: contextRoot + 'wdqyhz/fprw.html',
					  scrollbar: false,
					  resize: false,
					  title:'分配任务'
				});
	   	}
	   	
	   	/** 批量分配任务  */
	   	function handoutTaskBatch(){
	   		var seles = $("#qyhzTable").datagrid('getSelections');
	   		if(seles.length>0){
	   			var QYXXIDS = [];
	   			$.each(seles, function(i,item){
	   				QYXXIDS.push(item.QYXXID);
	   			})
	   			StoreCache.setCache("QYXXIDS",QYXXIDS.join(","));
	   			StoreCache.setCache("qyxxArr",JSON.stringify(seles));
	   			parent.layer.open({
					  type: 2,
					  area: ["80%", "80%"],
					  content: contextRoot + 'wdqyhz/fprwBatch.html',
					  scrollbar: false,
					  resize: false,
					  title:'批量分配任务',
				});
	   		}else{
	   			$.QuickAlert.alertFail({content: '请选择至少一条数据'});
	   		}
	   	}
	   	
	   	/** 修改服务 */
		function updateTask(){
			var seles = $("#yfprwTable").datagrid('getSelections');
	   		if(seles.length>0){
	   			StoreCache.setCache("updateData",seles);
	   			parent.layer.open({
					  type: 2,
					  area: ["80%", "600px"],
					  content: contextRoot + 'wdqyhz/updateYfprw.html',
					  scrollbar: false,
					  resize: false,
					  title:'修改服务',
					  end: function(){
						  if(StoreCache.removeCache("refresh",true)){
							  $("#yfprwTable").datagrid("load");
						  }
					  }
				});
	   		}else{
	   			$.QuickAlert.alertFail({content: '请选择至少一条数据'});
	   		}
		}
		
		/** 删除服务 */
		function deleteTask(){
			var seles = $("#yfprwTable").datagrid('getSelections');
	   		if(seles.length>0){
	   			
	   			StoreCache.setCache("deleteData",seles);
	   			parent.layer.open({
					  type: 2,
					  area: ["80%", "600px"],
					  content: contextRoot + 'wdqyhz/deleteYfprw.html',
					  scrollbar: false,
					  resize: false,
					  title:'删除服务',
					  end: function(){
						  if(StoreCache.removeCache("refresh",true)){
							  $("#yfprwTable").datagrid("load");
						  }
					  }
				});
	   		}else{
	   			$.QuickAlert.alertFail({content: '请选择至少一条数据'});
	   		}
		}
		
    	
    	/** 初始化table方法  */
    	var initTableMethod = {
    			qyhzTable: function(){
	    				$("#qyhzTable").datagrid({
	    				idField : "QYXXID",
	    				striped : true,
	    				clickToSelect: true,
	    				fitColumns: true,
	    				fit:true,
	    				scrollbarSize:15,
	    				border:false,
	    				columns : [[
	    						{field: "xz",checkbox:true},
	    						{field: "XM",title: "姓名",width:30, align:'center'},
	    						{field: "ZJHM",title : "证件号码",width:60, align:'center',formatter:function(value){
	    							var reg = /.{8}$/;
	    							return value.replace(reg,'********');
	    						}},
	    						{field: "SJHM",title: "手机号码",width:60, align:'center'},
	    						{field: "JTZZ",title: "家庭住址",width:120, align:'left',formatter:function(value){
	   								return '<span title="'+value+'">'+value+'</span>';
	   							}},
	    						{field: "RQFLMC",title: "人群分类",width:60, align:'left',formatter:function(value){
	   								return '<span title="'+value+'">'+value+'</span>';
	   							}},
	    						{field: "QYSJ",title: "签约时间",width:75, align:'center', formatter:function(value){
									/*if(!StringUtils.isEmpty(value)){
										return value.substring(0,10);
									}*/
									return value;
								}},
	    						{field: "TDMC",title: "签约团队",width:60, align:'center'},
	    						{field: "FWBMC",title: "签约服务包",width:90, align:'center',formatter:function(value){
                                    return '<span title="'+value+'">'+value+'</span>';
                                }},
	    						{field: "cz",title: "操作",width:60,align:'center', formatter:function(value,row,index){
	    							row = JSON.stringify(row).replace(/"/g, '&quot;'); 
	    							var s = '<span class="spanBtn" onclick="toCkfw('+ row +')">查看服务</span>';
	    							var x = '<span class="spanBtn" onclick="handoutTask('+ row +')">分配服务</span>';
	    							return s + "&nbsp;&nbsp;" + x;
	    						}} 
	    				]],
	    				pagination : true,
	    				pageList: [10, 20, 50, 100, 200],
	    				method : "post",
	    				onBeforeLoad : function(params) {
	    					//params.QYLX = '01';
	    					//params.TDJS = 1; //团队长
	    					//params.USERID = parent.userInfo.USERID;
	    					getContainerDataByClassName('qyhzConditionBox','condition',params);//查询条件
                            formatTdid(params,'YLTDID');
	    				},
	    				onLoadSuccess: function(data){
	//     					alert(JSON.stringify(data))
	     				},
	    			})
	    		},
	    		yfprwTable: function(){
	    			$("#yfprwTable").datagrid({
						idField : "FPFWID",
						striped : true,
						clickToSelect: true,
						fitColumns: true,
						fit:true,
						scrollbarSize:0,
						columns : [[
								{field: "xz",checkbox:true},
								{field: "XM",title: "签约居民",width:40, align:'center'},
								{field: "FWDX",title: "服务对象",width:40, align:'center'},
								{field: "FWMC",title: "服务项",width:60, align:'center',formatter:function(value){
                                    return '<span title="'+value+'">'+value+'</span>';
                                }},
								{field: "FWNR",title: "服务项内容",width:120, align:'center',formatter:function(value){
                                    return '<span title="'+value+'">'+value+'</span>';
                                }},
								{field: "FWBMC",title: "签约服务包",width:60, align:'center',formatter:function(value){
                                    if(StringUtils.isEmpty(value)){
                                        return '<span class="fdztCss">医保服务项</span>';
                                    }else{
                                        return '<span title="'+ value +'">'+ value + '</span>'
                                    }
                                }},
								{field: "QYTD",title: "签约团队",width:60, align:'center',formatter:function(value){
                                    return '<span title="'+value+'">'+value+'</span>';
                                }},
								{field: "FWRY",title: "服务人员",width:60, align:'center'},
								{field: "YQFWSJ",title: "预期服务时间",width:60, align:'center',formatter: function(value){
									if(!StringUtils.isEmpty(value)){
										return value.substring(0,10);
									}
								}},
						]],
						pagination : true,
						pageList: [10, 20, 50, 100, 200],
						method : "post",
						url: contextRoot + "wdqyhz/queryYfprwByPage.service",
						onBeforeLoad : function(params) {
// 							params.FWZT = 0;
							getContainerDataByClassName('yfprwConditionBox','condition',params);//查询条件
							formatTdid(params,'TDID');
						},
						onLoadSuccess: function(data){
	// 						alert(JSON.stringify(data))
							//$("#yfprwTable").datagrid('unselectAll');
							$("#yfprwTable").datagrid('clearSelections')
		 				},
					});
	    		}
    	}
    	
    	/** 团队为空时，查询所有团队  */
    	function formatTdid(params,field){
			if(StringUtils.isEmpty(params[field])){
				var tdidArr = [];
				$("#TDID option").each(function(){
					var value = $(this).val();
					if(!StringUtils.isEmpty(value)){
						tdidArr.push(value);
					}
				})
				params[field] = tdidArr.join(',');
			}
		}
    	
    	/** 导出 */
	   	function download(){
	   		var params = {};
	   		params.TDID = $("#TDID").val();
            formatTdid(params,'TDID');
	   		$("#TDIDS").val(params.TDID);
	   		$("#downloadForm")[0].submit();
	   	}
    </script>

  </head>
  
  <body style="visibility:hidden">
    <div id="tabs" class="easyui-tabs" fit="true" border="false">
    	<div title="分配任务">
    		<div class="easyui-layout" border="false" fit="true">
				<div region="north" class="north" border="false" >
					<table class="form-table" id="qyhzConditionBox">
						<tr>
							<td class="td-text">姓名：</td>
							<td class="td-content">
								<input name="XM" class="form-control condition"  style="width: 100%;">
							</td>
							<td class="td-text">证件号码：</td>
							<td class="td-content">
								<div style="display: inline;">
									<input name="ZJHM" class="form-control condition" style="width: 100%;" />
								</div>
							</td>
							<td class="td-text">人群分类：</td>
							<td class="td-content">
								<select name="RQFL_XMDM" cacheTable="TB_ZY_RQFL" class="form-control condition" style="width: 100%;">
									<option value="">请选择</option>
								</select>
							</td>
							<td class="td-text" style="width:150px;text-align:center">
								<button id="btnQuery_fpfw" class="btn btn-info" type="button" onclick="btnQueryHandler_fpfw()">查询</button>
							</td>
						</tr>
						<tr class="activeQuery">
							<td class="td-text">签约日期：</td>
							<td class="td-content">
								 <input id="QYSJ_start" name="QYSJ_start" id="QYSJ_start" class="laydate-icon condition"/>
							</td>
							<td class="td-text">至：</td>
							<td class="td-content">
								<input id="QYSJ_end" name="QYSJ_end" id="QYSJ_end" class="laydate-icon condition"/>
							</td>
							<td class="td-text">签约团队：</td>
							<td class="td-content">
								<select id="YLTDID" name="YLTDID" class="form-control tdxxSelect condition" style="width: 100%;">
									<option value="">请选择</option>
								</select>
							</td>
							<td class="td-text"></td>
						</tr>
					</table>
					<div style="margin-top:10px;margin-left:10px;">
						<button type="button" onclick="handoutTaskBatch()">批量分配任务</button>
					</div>
				</div>
				<div region="center" border="false">
					<table id="qyhzTable"></table>
				</div>
			</div>
    	</div>
    	
    	<div title="任务管理">
    		<div class="easyui-layout" fit="true" border="false">
				<div region="north" class="north" >
					<form action="downloadYfprw.service" method="post" enctype="multipart/form-data" id="downloadForm">
						<table class="form-table" id="yfprwConditionBox">
							<tr>
								<td class="td-text">签约居民：</td>
								<td class="td-content">
									<input type="hidden" name="FWZT" value="0" class="condition"/>
									<input type="hidden" name="TDIDS" id="TDIDS"/>
									
									<input name="XM" class="form-control condition"  style="width: 100%;">
								</td>
								<td class="td-text">服务人员：</td>
								<td class="td-content">
									<div style="display: inline;">
										<input name="FWRY" class="form-control condition" style="width: 100%;" />
									</div>
								</td>
								<td class="td-text" style="width:120px;">签约服务包：</td>
								<td class="td-content">
									<select id="FWBID" name="FWBID" class="form-control condition" style="width: 100%;">
										<option value="">请选择</option>
									</select>
								</td>
								<td style="width:180px;text-align:center;">
									<button class="btn btn-info" type="button" onclick="btnQueryHandler_rwgl()"  id="btnQuery_rwgl">查询</button>
									<button class="btn btn-info" type="button" onclick="download()">导出</button>
								</td>
							</tr>
							<tr>
								<td class="td-text" style="width:120px;">预期服务时间：</td>
								<td class="td-content">
									<input name="YQFWSJ" onclick="laydate()" class="form-control laydate-icon condition" style="width: 100%;" />
								</td>
								<td class="td-text">签约团队：</td>
								<td class="td-content">
									<select id="TDID" name="TDID" class="form-control tdxxSelect condition" style="width: 100%;">
										<option value="">请选择</option>
									</select>
								</td>
							</tr>
						</table>
					</form>
					<div style="margin-top:10px;margin-left:10px;">
						<button class="btn btn-info" type="button" onclick="updateTask()">修改服务</button>
						<button class="btn btn-info" type="button" onclick="deleteTask()">删除服务</button>
					</div>
				</div>
				<div region="center" border="false">
					<table id="yfprwTable" border="false"></table>
				</div>
			</div>
    	</div>
    </div>
    
  </body>
</html>
